<?php

namespace app\common\util\plug;

use app\common\util\base\BaseObserver;
use app\common\util\base\BaseServer;
use EasyZip\ZipHandle;
use think\Exception;
use app\common\util\FileUtil;

class PlugUnzip extends BaseObserver
{
    public function handle()
    {
        $path = $this->server->getPlugTempPath();
        if (!is_dir($path)) {
            ZipHandle::unzip($this->server->getFile()->getPathname(), $path);
            $configFile = $path.'v-plug.yaml';
            if (!file_exists($configFile)) {
                FileUtil::delDirAndFile($path);   //删除目录
                throw new Exception('非本系统插件');
            }
        }
        return true;
    }
}